package org.example.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.Shippinglist;
import org.example.mapper.ShippinglistMapper;
import org.example.service.IShippinglistService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author scs
 * @since 2025-03-05
 */
@Service
public class ShippinglistServiceImpl extends ServiceImpl<ShippinglistMapper, Shippinglist> implements IShippinglistService {
    public Map<Integer, Double> getMinPriceByCidList(List<Integer> cidList) {
        QueryWrapper<Shippinglist> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("cid", "MIN(price) AS min_price")
                .in("cid", cidList)  // 限制查询的cid范围（与Boat列表相关）
                .groupBy("cid");

        List<Map<String, Object>> result = listMaps(queryWrapper);

        // 将结果转为 Map<cid, min_price>
        return result.stream()
                .collect(Collectors.toMap(
                        e -> (Integer) e.get("cid"),
                        e -> (Double) e.get("min_price")
                ));
    }
}
